package com.giscloud.limp.controller;

import java.util.Arrays;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.beans.factory.annotation.Autowired;

import com.giscloud.limp.entity.LegalProject;
import com.giscloud.limp.service.LegalProjectService;
import com.giscloud.limp.entity.dto.LegalProjectDTO;
import com.giscloud.datasource.page.PageInfo;
import com.giscloud.commons.model.Result;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.*;


/**
 * 法务项目管理
 *
 * @author giscloud
 * @email giscloud@giscloud.com
 * @date 2020-06-08 16:06:40
 */
@RestController
@RequestMapping("/limp/legalproject")
@Log4j2
public class LegalProjectController {

    private final LegalProjectService legalProjectService;

    @Autowired
    public LegalProjectController(LegalProjectService legalProjectService) {
        this.legalProjectService = legalProjectService;
    }
    /**
     * 列表
     */
    @RequestMapping("/list")
    public Result<PageInfo<LegalProject>> list(@RequestBody LegalProjectDTO legalProjectDTO){
        PageInfo page = legalProjectService.queryPage(legalProjectDTO);
        return Result.success(page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{legalProjectId}")
    public Result<LegalProject> info(@PathVariable("legalProjectId") Integer legalProjectId){
		LegalProject legalProject = legalProjectService.getById(legalProjectId);
        return Result.success(legalProject);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public Result save(@RequestBody LegalProject legalProject){
        return legalProjectService.save(legalProject);
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public Result update(@RequestBody LegalProject legalProject){
        return legalProjectService.updateById(legalProject);
    }

    /**
     * 删除(直接传数组对象即可，如：[1],[1,2]支持批量删除)
     */
    @RequestMapping("/delete")
    public Result delete(@RequestBody Integer[] legalProjectIds){
        return legalProjectService.removeByIds(Arrays.asList(legalProjectIds));
    }

}
